package com.example.hasee.zhcd.Activities.ChuanWu;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hasee.zhcd.Adapters.CgsDetailAdapter;
import com.example.hasee.zhcd.Adapters.WayBillAdapter;
import com.example.hasee.zhcd.Base.BaseActivity;
import com.example.hasee.zhcd.Bean.EventMsg;
import com.example.hasee.zhcd.R;
import com.example.hasee.zhcd.Util.GlobalParameter;
import com.example.hasee.zhcd.Util.ProgressDialogUtils;

import org.json.JSONArray;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

import static com.example.hasee.zhcd.R.id.cgs_detail_list;

/**
 * Created by hasee on 2018/5/28.
 */

public class WayBillActivity extends BaseActivity {
    private HashMap<String, String> map = (HashMap<String, String>) GlobalParameter.get("loginmap");
    private TextView title;
    private ImageView back;
    private ImageView home;
    private ListView way_bill_list;
    private ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    private WayBillAdapter adapter;
    private String strSYN;

    @Override
    public int contentViewId() {
        return R.layout.activity_waybill;
    }

    @Override
    public void set() {
        title.setText("运单登记信息");
        back.setOnClickListener(this);
        home.setVisibility(View.INVISIBLE);
        getDetaillist();
    }

    @Override
    public void init() {
        strSYN = getIntent().getExtras().getString("strSYN");
        back = (ImageView) findViewById(R.id.back);
        home = (ImageView) findViewById(R.id.home);
        title = (TextView) findViewById(R.id.centertitle);
        way_bill_list = (ListView) findViewById(R.id.way_bill_list);
    }

    private void getDetaillist() {
        ProgressDialogUtils.createProgressDialog(WayBillActivity.this, "正在加载列表...");
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("strSYN", strSYN);
        httpUtils.get("ZHCW_YD", map, "ZHCW_YD");
    }

    @Override
    public void getEventData(EventMsg msg) {
        switch (msg.getAction()) {
            case "ZHCW_YD":
                Log.e("ZHCW_YD", msg.getMsg());
                ProgressDialogUtils.closeProgressDialog();
                try {
                    JSONObject json = new JSONObject(msg.getMsg());
                    String rspcode = json.getString("rspcode");
                    String rspmessage = json.getString("rspmessage");
                    if ("0".equals(rspcode)) {
                        JSONArray data = json.getJSONArray("data");
                        list.clear();
                        way_bill_list.setVisibility(View.VISIBLE);
                        for (int i = 0; i < data.length(); i++) {
                            HashMap<String, String> map = new HashMap<String, String>();
                            map.put("fydh", data.getJSONObject(i).getString("fydh"));
                            map.put("fcgs", data.getJSONObject(i).getString("fcgs"));
                            map.put("fjhd", data.getJSONObject(i).getString("fjhd"));
                            map.put("ffhr", data.getJSONObject(i).getString("ffhr"));
                            map.put("fshr", data.getJSONObject(i).getString("fshr"));
                            list.add(map);
                        }
                        adapter = new WayBillAdapter(WayBillActivity.this, list);
                        way_bill_list.setAdapter(adapter);
                    } else {
                        way_bill_list.setVisibility(View.GONE);
                        Toast.makeText(WayBillActivity.this, rspmessage, Toast.LENGTH_LONG).show();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
        }
    }
}